﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using UnwiseSource.ServiceReference1;

namespace UnwiseSource
{
    public partial class courses : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetCourses();
        }

        [WebMethod]
        public static string SaveLanguage(string lang)
        {
            HttpContext.Current.Session["language"] = lang;

            return lang;
        }

        public void GetCourses()
        {
            Service1Client unwiseSourceService = new Service1Client();
            string key = Helper.getconfigparam("SECID", "");
            string language = (string)Session["language"];
            if (language == "bg")
            {
                courses_header.InnerText = "Курсове";
            }
            else
            {
                courses_header.InnerText = "Courses";
            }

            try
            {
                List<v_Courses> courses = unwiseSourceService.GetCourses(key, language);
                course_content.Controls.Clear();
                foreach (var course in courses)
                {
                    string generatedHtml = GenerateHtml.GenerateCourse(course, language);
                    HtmlGenericControl link = new HtmlGenericControl("a");
                    link.InnerHtml = generatedHtml;
                    link.Attributes["href"] = "lectures.aspx?courseId=" + course.CourseId;
                    course_content.Controls.Add(link);
                }
            }
            catch (Exception ex)
            {
                Helper.LogErrorMsg(ex.ToString());
            }
        }
    }
}